<template>
  <router-link
    :to="{
      path: `/albums/${album.id}`,
      query: {
        fromPage: fromPage,
        title: album.title,
        description: album.description,
        date: album.date,
      },
    }"
    class="album-card"
  >
    <!-- 封面图片，比例固定，圆角阴影 -->
    <div class="album-cover">
      <img :src="album.coverImg" :alt="album.title" />
    </div>
    <!-- 信息区：标题、摘要、底部对齐的meta -->
    <div class="album-info">
      <div>
        <div class="album-title">{{ album.title }}</div>
        <div class="album-desc">{{ album.description }}</div>
      </div>
      <div class="album-meta">
        <div class="meta-left">
          <span><i class="ri-eye-line"></i> {{ album.views }}</span>
          <span><i class="ri-image-line"></i> {{ album.photoCount }}张</span>
        </div>
        <div class="meta-right">
          <span><i class="ri-calendar-line"></i> {{ formatDate(album.date) }}</span>
        </div>
      </div>
    </div>
  </router-link>
</template>

<script setup>
defineProps({
  album: {
    type: Object,
    required: true,
  },
  fromPage: {
    type: Number,
    default: 1,
  },
})

// 格式化日期为 yyyy.mm.dd
const formatDate = (dateString) => {
  if (!dateString) return ''
  const date = new Date(dateString)
  return `${date.getFullYear()}.${String(date.getMonth() + 1).padStart(2, '0')}.${String(date.getDate()).padStart(2, '0')}`
}

defineOptions({ name: 'AlbumCard' })
</script>

<style lang="scss" scoped>
// 单个相册卡片，固定高度，底部信息对齐
.album-card {
  display: flex;
  flex-direction: column;
  height: 292px; // 固定卡片高度
  border-radius: 0.6rem;
  overflow: hidden;
  background: var(--bg-base, #fff);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
  text-decoration: none;
  transition:
    box-shadow 0.2s,
    transform 0.2s;
  cursor: pointer;
  &:hover {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px) scale(1.015);
  }
}

// 封面图片区域，固定高度，图片自适应裁剪
.album-cover {
  width: 100%;
  height: 160px; // 固定封面图片高度
  background: #f5f6fa;
  position: relative;
  flex-shrink: 0; // 防止图片区域被压缩
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s cubic-bezier(0.4, 2, 0.6, 1);
  }
}

// 信息区，flex布局，底部meta始终对齐，摘要不会被遮挡
.album-info {
  display: flex;
  flex-direction: column;
  flex: 1; // 占据剩余空间
  padding: 1rem 1.1rem;
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.97) 90%, rgba(255, 255, 255, 0.7) 100%);
  min-height: 120px; // 确保信息区域有足够空间
  .album-title {
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--text-primary, #222);
    margin-bottom: 0.3rem;
    letter-spacing: 0.01em;
    line-height: 1.3;
  }
  .album-desc {
    font-size: 0.92rem;
    color: var(--text-secondary, #666);
    line-height: 1.5;
    margin-bottom: 0.3rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.8em;
    max-height: 2.8em;
  }
  .album-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.5rem; // 使用padding-top替代margin-top，控制间距
    padding-bottom: 0.7rem;
    font-size: 0.89rem;
    color: var(--text-tertiary, #999);
    .meta-left {
      display: flex;
      align-items: center;
      gap: 1.1rem;
      span {
        display: flex;
        align-items: center;
        gap: 0.2em;
      }
      i {
        font-size: 1em;
        vertical-align: middle;
        display: flex;
        align-items: center;
      }
    }
    .meta-right {
      display: flex;
      align-items: center;
      span {
        display: flex;
        align-items: center;
        gap: 0.2em;
      }
      i {
        font-size: 1em;
        vertical-align: middle;
        display: flex;
        align-items: center;
      }
    }
  }
}

// 移动端适配
@media (max-width: 500px) {
  .album-card {
    height: 270px; // 进一步增加卡片高度，确保描述文字完整显示
  }

  .album-cover {
    height: 150px; // 移动端封面图片高度
    flex-shrink: 0;
  }

  .album-info {
    min-height: 160px; // 增加信息区域高度，确保描述文字完整显示
    padding: 0.75rem 1rem; // 减少内边距

    .album-title {
      font-size: 1rem;
      margin-bottom: 0.25rem;
    }

    .album-desc {
      font-size: 0.875rem;
      line-height: 1.5; // 增加行高，确保文字完整显示
      margin-bottom: 0.5rem; // 增加描述和元数据之间的间距
      min-height: 2.65em; // 增加最小高度，确保两行文字完整显示
      max-height: 2.65em;
      padding-bottom: 2px; // 添加底部内边距，防止文字被截断
    }

    .album-meta {
      font-size: 0.8125rem;
      padding-top: 0.25rem; // 减少顶部间距
      padding-bottom: 0.5rem;

      .meta-left {
        gap: 0.75rem;
      }
    }
  }
}

// 暗色模式适配
:deep(html.dark) {
  .album-card {
    background: var(--bg-light, #232425);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.18);
  }
  .album-info {
    background: linear-gradient(0deg, rgba(34, 36, 37, 0.98) 90%, rgba(34, 36, 37, 0.7) 100%);
    .album-title {
      color: #fff;
    }
    .album-desc,
    .album-meta {
      color: #bbb;
    }
  }
}
</style>
